package br.com.testes;

import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
import java.awt.image.VolatileImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class GSprite {

	VolatileImage[] tiles;
    final int TILE_COLUMN_CNT = 3;   
    final int TILE_ROW_CNT = 4;
    final int TILE_WIDTH = 32;   
    final int TILE_HEIGHT = TILE_WIDTH;
    private AffineTransform transform = null;
    private Shape shape = null;
    BufferedImage[] sprites = null;
	
	public GSprite(String fileName){
		BufferedImage bigImg = null;
		try {
			bigImg = ImageIO.read(new File(fileName));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		// The above line throws an checked IOException which must be caught.

		final int width = 32;
		final int height = 32;
		final int rows = 4;
		final int cols = 3;
		sprites = new BufferedImage[rows * cols];

		for (int i = 0; i < rows; i++) {
		    for (int j = 0; j < cols; j++) {
		        sprites[(i * cols) + j] = bigImg.getSubimage( j * width, i * height, width, height);
		    }
		}
		transform = new AffineTransform();
		transform.setToIdentity();
	}
	
	public void draw(Graphics2D g2d)
	{
		//UGEVector2D pos = getDrawPosition();
//		g2d.setColor(Color.GREEN);
//		g2d.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer);
		g2d.drawImage(sprites[2], 50, 50, null);
		g2d.setTransform(transform);
		g2d.dispose();
		//g2d.translate((int)pos.getX(),(int)pos.getY());
//		g2d.fill(shape);
//		g2d.setTransform(transform);

	}
	
	
	
}
